#include "Point.h"

Point::Point()
{
	_x=0.0;
	_y=0.0;
	_z=0.0;
}

Point::~Point()
{

}

Point::Point(double newx, double newy, double newz) {
	_x = newx;
	_y = newy;
	_z = newz;
}

Point::Point(int newx, int newy, int newz) { 
	_x = (double) newx;
	_y = (double) newy;
	_z = (double) newz;
}

Point::Point(const Point &newposition) {
	_x = newposition._x;
	_y = newposition._y;
	_z = newposition._z;
}

Point Point::operator - () const {
  return Point(-_x, -_y, -_z);
}

void Point::operator *= (const int factor){
	_x*=factor;
	_y*=factor;
	_z*=factor;
}

void Point::operator *= (const double factor){
	_x*=factor;
	_y*=factor;
	_z*=factor;
}

void Point::operator /= (const int divisor){
	if(divisor == 0) return;
	_x/=(double) divisor;
	_y/=(double) divisor;
	_z/=(double) divisor;
}

void Point::operator /= (const double divisor){
	if(divisor == 0) return;
	_x/= divisor;
	_y/= divisor;
	_z/= divisor;
}

void Point::operator += (const Point& other){
	_x += other._x;
	_y += other._y;
	_z += other._z;
}

Point Point::operator - (const Point &other){
	return Point(_x-other._x,_y-other._y, _z-other._z);
}

Point Point::operator - (const Point &other) const {
	return Point(_x-other._x,_y-other._y, _z-other._z);
}

Point Point::operator + (const Point &other){
	return Point(_x+other._x,_y+other._y, _z+other._z);
}

Point& Point::operator=(const Point &other){
	_x = other._x;
	_y = other._y;
	_z = other._z;
	return *this;
}

Point Point::operator /(const double divisor)
{
	return Point(_x/divisor,_y/divisor, _z/divisor);
}

Point Point::operator *(const double factor)
{
	return Point(_x*factor,_y*factor, _z*factor);
}

void Point::normalize() {
  double abs = sqrt(_x*_x + _y*_y + _z*_z);
  _x /= abs; _y /= abs; _z /= abs;
}

Point Point::TransMatMultiply(double *transMat, Point inPoint)
{
	Point outPoint;

	outPoint._x = transMat[ 0]*inPoint._x +transMat[ 4]*inPoint._y +transMat[8] *inPoint._z +transMat[12];
	outPoint._y = transMat[ 1]*inPoint._x +transMat[ 5]*inPoint._y +transMat[9] *inPoint._z +transMat[13];
	outPoint._z = transMat[ 2]*inPoint._x +transMat[ 6]*inPoint._y +transMat[10]*inPoint._z +transMat[14];

	return outPoint;
}

